import { Module } from 'vuex'
import { AppState, RootState } from '../interface'
import { getStorage, setStorage, removeStorage } from '@/utils/auth'

const appModule: Module<AppState, RootState> = {
  namespaced: true,
  state: {
    collapsed: false,
    modeColor: true, // true light  false dark
    loginFormType: 1 // 0 登录 1 注册  2 忘记密码
  },
  mutations: {
    TOGGLE_SEATUS: (state, status) => {
      state.collapsed = status !== null ? status : !state.collapsed
    },
    TOGGLE_MODE_COLOR: (state, status) => {
      state.modeColor = status
      setStorage('USER_MODE_COLOR', state.modeColor)
    },
    TOGGLE_LOGIN_FORM_TYPE: (state, status) => {
      state.loginFormType = status
    }
  },
  actions: {
    toggleStatus({ commit }, params = null) {
      commit('TOGGLE_SEATUS', params)
    },
    toggleModeColor({ commit }, params = true) {
      commit('TOGGLE_MODE_COLOR', params)
    },
    toggleLoginFormType({ commit }, params = null) {
      commit('TOGGLE_LOGIN_FORM_TYPE', params)
    }
  }
}
export default appModule
